Repository navigation
sys/cpu: Use cntvct_el0 instead of cntpct_el0 on aarch64 - #712
hotline1337 wants to merge 1 commit into
Conversation
Firmware or hypervisors with CNTHCTL_EL2.EL1PCTEN cleared trap EL1 reads of CNTPCT_EL0 to EL2, triggering unhandled synchronous exceptions when no EL2 handler is present. CNTVCT_EL0 avoids this trap. Signed-off-by: hotline1337 <denuvo at tuta dot io>
|
imagine generating commit message with AI for code replacing cntpct_el0 with cntvct_el0 in 2 lines |
Those 2 lines are literally the difference between a boot failure and a working system on NVIDIA N1X Spark and DGX Spark. Leaving zero context in git blame for why a bootloader swapped CNTPCT_EL0 to CNTVCT_EL0 to bypass CNTHCTL_EL2.EL1PCTEN traps is just lazy |
|
@hotline1337 The point @makaroneder was making isn't the fact that there are commit descriptions (which there don't seem to be, i can't see any commit description). And as you have already noted, context is important, especially for changes like this, please add a commit description. PR descriptions don't show up in the git log. |
Forgot to force push. Resolved. |
Summary
CNTPCT_EL0) to the virtual counter (CNTVCT_EL0) incommon/sys/cpu.handchecks/payloads/limine/arch_aarch64.c.Background & Problem
Per the ARM Architecture Reference Manual for A-profile architecture (
ARM DDI 0487),CNTPCT_EL0reads the physical counter, whereasCNTVCT_EL0reads the virtual counter, i.e. the physical count minusCNTVOFF_EL2(treated as zero when EL2 is absent or disabled). Access from lower exception levels may be trapped by the hypervisor.CNTHCTL_EL2.EL1PCTENis cleared, accessingCNTPCT_EL0from EL1 traps to EL2. Depending on hypervisor configuration, this either incurs costly VM-exit emulation overhead on every timer poll or triggers an unhandled synchronous exception.CNTVCT_EL0is intended for EL1/EL0 consumers, executes natively in hardware without trapping to EL2 under standard virtualisation setups, and provides a consistent monotonic counter on both bare metal and virtualised guests.Changes
common/sys/cpu.h: Updatedrdtsc()on AArch64 to readcntvct_el0instead ofcntpct_el0.checks/payloads/limine/arch_aarch64.c: Updatedarch_counter()in the Limine test payload to readcntvct_el0instead ofcntpct_el0.Verification & Testing
-Werrorwith 0 warnings and 0 errors.CNTVCT_EL0cleanly without exceptions.